import javax.swing.JPanel;

import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.Component;
import javax.swing.Box;
import javax.swing.JTextArea;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JComboBox;
import javax.swing.JCheckBox;
import java.awt.Checkbox;


public class EditUserGUI extends JPanel {
    int location;
    User user = new User();
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    private JTextField textField_3;
    private JTextField textField_4;
    private JTextField textField_6;
    private JTextField textField_7;
    private JTextField textField_8;
    private JTextField textField_9;
    private JTextField textField_10;
    private JTextField textField_11;
    private JTextField textField_5;
    public EditUserGUI() {
        setLayout(null);
        
        
        
        
        
        final Checkbox checkbox_1 = new Checkbox("");
        checkbox_1.setBounds(411, 147, 95, 22);
        add(checkbox_1);
        
        final Checkbox checkbox_2 = new Checkbox("");
        checkbox_2.setBounds(411, 169, 95, 22);
        add(checkbox_2);
        
        final Checkbox checkbox_3 = new Checkbox("");
        checkbox_3.setBounds(411, 191, 95, 22);
        add(checkbox_3);
        
        JLabel lblName = new JLabel("Name");
        lblName.setBounds(9, 8, 45, 14);
        add(lblName);
        
        textField = new JTextField();
        textField.setBounds(64, 5, 86, 20);
        add(textField);
        textField.setColumns(10);
        
        JLabel lblAddress = new JLabel("Address");
        lblAddress.setBounds(160, 8, 96, 14);
        add(lblAddress);
        
        textField_1 = new JTextField();
        textField_1.setBounds(267, 5, 86, 20);
        add(textField_1);
        textField_1.setColumns(10);
        
        JLabel lblNewLabel = new JLabel("Phone");
        lblNewLabel.setBounds(9, 33, 45, 14);
        add(lblNewLabel);
        
        textField_2 = new JTextField();
        textField_2.setBounds(64, 30, 86, 20);
        add(textField_2);
        textField_2.setColumns(10);
        
        JLabel lblCell = new JLabel("Cell");
        lblCell.setBounds(160, 33, 96, 14);
        add(lblCell);
        
        textField_3 = new JTextField();
        textField_3.setBounds(267, 30, 86, 20);
        add(textField_3);
        textField_3.setColumns(10);
        
        JLabel lblEmail = new JLabel("Email");
        lblEmail.setBounds(12, 58, 42, 14);
        add(lblEmail);
        
        textField_4 = new JTextField();
        textField_4.setBounds(64, 55, 86, 20);
        add(textField_4);
        textField_4.setColumns(10);
        
        JLabel lblNewLabel_1 = new JLabel("Gender");
        lblNewLabel_1.setBounds(160, 58, 96, 14);
        add(lblNewLabel_1);
        
        JLabel lblNewLabel_2 = new JLabel("Pharmacy");
        lblNewLabel_2.setBounds(10, 83, 47, 14);
        add(lblNewLabel_2);
        
        textField_6 = new JTextField();
        textField_6.setBounds(64, 80, 86, 20);
        add(textField_6);
        textField_6.setColumns(10);
        
        JLabel lblInsurance = new JLabel("Insurance");
        lblInsurance.setBounds(153, 83, 103, 14);
        add(lblInsurance);
        
        textField_7 = new JTextField();
        textField_7.setBounds(267, 80, 86, 20);
        add(textField_7);
        textField_7.setColumns(10);
        
        JLabel lblAllergies = new JLabel("Allergies");
        lblAllergies.setBounds(6, 127, 40, 14);
        add(lblAllergies);
        
        JButton btnCreate = new JButton("Edit");
        btnCreate.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                user.setAddress(textField_1.getText());
                user.setAllergies(textField_11.getText());
                user.setInsurance(textField_7.getText());
                user.setSSN(Integer.parseInt(textField_8.getText()));
                user.setEmail(textField_4.getText());
                user.setCellPhone(textField_3.getText());
                user.setPhone(textField_2.getText());
                user.setUserName(textField_10.getText());
                user.setPassword(textField_9.getText());
                user.setName(textField.getText());
                boolean[] roles = new boolean[4];
                
                roles[0] = true;
                roles[1] = checkbox_1.getState();
                roles[2] = checkbox_2.getState();
                roles[3] = checkbox_3.getState();
                
                user.setRoles(roles);
                
                String gen = textField_5.getText();
                if ("MALE".equals(gen)){
                	user.setGender(Gender.MALE);
                }
                else if ("FEMALE".equals(gen)){
                	user.setGender(Gender.FEMALE);
                }
                else{
                	user.setGender(Gender.NULL);
                }
                
                user.setPharmacy(textField_6.getText());
                
                location = 3;
                
            }
        });
        btnCreate.setBounds(197, 277, 118, 23);
        add(btnCreate);
        
        JButton btnCancel = new JButton("Cancel");
        btnCancel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                location = -1;
            }
        });
        btnCancel.setBounds(325, 277, 125, 23);
        add(btnCancel);
        
        JButton btnNewButton = new JButton("Delete User");
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                location = -4;
            }
        });
        btnNewButton.setBounds(9, 277, 168, 23);
        add(btnNewButton);
        
        JComboBox comboBox_1 = new JComboBox();
        comboBox_1.setBounds(460, 55, 28, 20);
        add(comboBox_1);
        
        JLabel lblSocialSecurity = new JLabel("Social Security");
        lblSocialSecurity.setBounds(11, 174, 112, 14);
        add(lblSocialSecurity);
        
        textField_8 = new JTextField();
        textField_8.setBounds(133, 171, 86, 20);
        add(textField_8);
        textField_8.setColumns(10);
        
        JLabel lblRole = new JLabel("Role");
        lblRole.setBounds(401, 103, 46, 14);
        add(lblRole);
        
        JLabel lblNewLabel_3 = new JLabel("Suspension");
        lblNewLabel_3.setBounds(401, 58, 77, 14);
        add(lblNewLabel_3);
        
        JLabel lblPassword = new JLabel("Password");
        lblPassword.setBounds(12, 199, 111, 14);
        add(lblPassword);
        
        textField_9 = new JTextField();
        textField_9.setBounds(133, 196, 86, 20);
        add(textField_9);
        textField_9.setColumns(10);
        
        JLabel lblUsername = new JLabel("Username");
        lblUsername.setBounds(11, 224, 112, 14);
        add(lblUsername);
        
        textField_10 = new JTextField();
        textField_10.setBounds(133, 221, 86, 20);
        add(textField_10);
        textField_10.setColumns(10);
        
        textField_11 = new JTextField();
        textField_11.setColumns(10);
        textField_11.setBounds(56, 124, 297, 40);
        add(textField_11);
        
        JLabel lblNurse = new JLabel("Nurse");
        lblNurse.setBounds(366, 150, 112, 14);
        add(lblNurse);
        
        JLabel lblDoctor = new JLabel("Doctor");
        lblDoctor.setBounds(366, 174, 112, 14);
        add(lblDoctor);
        
        JLabel lblAdmin = new JLabel("Admin");
        lblAdmin.setBounds(366, 199, 112, 14);
        add(lblAdmin);
        
        textField_5 = new JTextField();
        textField_5.setBounds(267, 51, 86, 28);
        add(textField_5);
        textField_5.setColumns(10);
        
        
    }
    
    public int getLoc()
    {
        return location;
    }
    public void setLoc(int i)
    {
        location = i;
    }
    
    public void setUser(User input)
    {
        user = input;
    }
    public User getUser()
    {
        return user;
    }
    
    public void act()
    {
    	System.out.println("worked");
        textField_1.setText(user.getAddress());
        textField_11.setText(user.getAllergies());
        textField_7.setText(user.getInsurance());
        textField_8.setText(String.valueOf(user.getSSN()));
        textField_4.setText(user.getEmail());
        textField_3.setText(user.getCellPhone());
        textField_2.setText(user.getPhone());
        textField_10.setText(user.getUserName());
        textField_9.setText(user.getPassword());
        textField.setText(user.getName());
        textField_5.setText(user.getGender().toString());
        textField_6.setText(user.getPharmacy());
        
    }
}
